#!/bin/bash

	echo "=========== BUILD SQUID ===========";

	echo "1. Distclean";
    make distclean;
    
    echo "2. Bootstrap";
    sh ./bootstrap.sh; 
    
    echo "3.For 32/64 bit"
    os=`uname -m`
    if [ $os = "x86_64" ]
    then 
    	echo "For 64 bit"
    	export CFLAGS="-O2 -pipe -m64 -march=core2 -fomit-frame-pointer -s" 
    	export CXXFLAGS="-O2 -pipe -m64 -march=core2 -fomit-frame-pointer -s"
    	export LDFLAGS="-m64 -s -Wl,-O1"
        echo "4. Configure";
        ./configure '--build=x86_64-linux-gnu' 'build_alias=x86_64-linux-gnu' '--prefix=/usr' '--includedir=${prefix}/include' '--mandir=${prefix}/share/man' '--infodir=${prefix}/share/info' '--sysconfdir=/etc' '--localstatedir=/var' '--libexecdir=${prefix}/lib/squid3' '--disable-maintainer-mode' '--disable-dependency-tracking' '--srcdir=.' '--datadir=/usr/share/squid3' '--sysconfdir=/etc/squid3' '--mandir=/usr/share/man' '--with-cppunit-basedir=/usr' '--enable-inline' '--enable-async-io=64' '--enable-storeio=aufs' '--enable-diskio=AIO,Blocking,DiskDaemon,DiskThreads' '--enable-removal-policies=heap,lru' '--enable-digest-pools' '--enable-snmp' '--enable-htcp' '--disable-carp' '--enable-large-files' '--enable-underscores' '--with-filedescriptors=131072' '--enable-linux-netfilter' '--with-default-user=squid' '-enable-follow-x-forwarded-for' '--enable-ecap' '--enable-kill-parent-hack';
    else
    	echo "For 32 bit"
	export CFLAGS="-O2 -pipe -m32 -fomit-frame-pointer -s"
	export CXXFLAGS="-O2 -pipe -m32 -fomit-frame-pointer -s"
	export LDFLAGS="-m32 -s -Wl,-O1"
        echo "4. Configure";
        ./configure '--prefix=/usr' '--includedir=${prefix}/include' '--mandir=${prefix}/share/man' '--infodir=${prefix}/share/info' '--sysconfdir=/etc' '--localstatedir=/var' '--libexecdir=${prefix}/lib/squid3' '--disable-maintainer-mode' '--disable-dependency-tracking' '--srcdir=.' '--datadir=/usr/share/squid3' '--sysconfdir=/etc/squid3' '--mandir=/usr/share/man' '--with-cppunit-basedir=/usr' '--enable-inline' '--enable-async-io=64' '--enable-storeio=aufs' '--enable-diskio=AIO,Blocking,DiskDaemon,DiskThreads' '--enable-removal-policies=heap,lru' '--enable-digest-pools' '--enable-snmp' '--enable-htcp' '--disable-carp' '--enable-large-files' '--enable-underscores' '--with-filedescriptors=131072' '--enable-linux-netfilter' '--with-default-user=squid' '-enable-follow-x-forwarded-for' '--enable-ecap' '--enable-kill-parent-hack';
   fi 
    echo "5. Make";
    make -j 300; 
    
    if [ $? != 0 ]; then echo "Compilation FAILED!!!"; exit; fi;
    
    echo "6. Kill SQUID";
#    sh ./kill_squid.sh
   
    echo "7. Deploy";
    checkinstall --install=no;
    
